<template>
  <div>
    <h4 class="text-center">组织的志愿活动</h4>
    <table class="table">
      <thead>
        <tr>
          <th>活动名称</th>
          <th>活动类别</th>
          <th>活动创建时间</th>
          <th>活动预计完成时间</th>
          <th>活动完成情况</th>
          <th>活动详情</th>
          <th>操作</th>
          <th>结束</th>
          <th>志愿者</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="item in MyOrganizationVoluntarys" :key="item.activityID" :class="item.isCompleted?'table-success':'table-warning'">
          <td>{{ item.activityName }}</td>
          <td>{{ item.activityTypeName }}</td>
          <td>{{ item.activityCreateTime }}</td>
          <td>{{ item.activityCompleteTime }}</td>
          <td>{{ item.isCompleted?'已完成':'未完成' }}</td>
          <td>
            <router-link :to="'MyOrganizationVoluntary/Show/'+item.activityID">查看详情</router-link>
          </td>
          <td>
            <router-link :to="'MyOrganizationVoluntary/Manager/'+item.activityID">管理志愿</router-link>
          </td>
          <td>
            <a @click="ConfirmActivityComplete(item.activityID)" class="user-select-none" v-show="!item.isCompleted">提前完成志愿</a>
          </td>
          <td>
            <router-link :to="'MyOrganizationVoluntary/Voluntary/'+item.activityID">查看参加志愿者</router-link>
          </td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script>
export default {
  name: 'MyOrganizationVoluntary',
  data() {
    return {
      MyOrganizationVoluntarys: null
    }
  },
  methods: {
    ConfirmActivityComplete(id) {
      if (confirm('确认是否提前完成')) {
        this.axios.get(`/SelectIdentity/Organization/ConfirmActivityComplete?ActivityID=${id}`).then(res => {
          if (res.data) {
            for (let i = 0; i < this.MyOrganizationVoluntarys.length; i++) {
              if (this.MyOrganizationVoluntarys[i].activityID === id) {
                console.log(this.MyOrganizationVoluntarys[i].activityID)
                item.isComplete = true
              }
              alert('确定完成成功')
            }
          }
        })
      }
    }
  },
  created() {
    const organizationID = JSON.parse(localStorage.getItem('Person')).organizationID
    this.axios.get(`/SelectIdentity/Organization/GetActivityByOrganizationID?OrganizationID=${organizationID}`).then(res => {
      if (res.data != null) {
        this.MyOrganizationVoluntarys = res.data
      }
    })
  }
}
</script>

<style lang="less" scoped>
</style>